import 'package:flutter/material.dart';
import 'package:flutter_eve_plugin/components/ye_xiu/archives/archives_center.dart';
import 'package:flutter_eve_plugin/components/ye_xiu/archives/archives_footer.dart';
import 'package:flutter_eve_plugin/components/ye_xiu/archives/archives_top.dart';
import 'package:flutter_eve_plugin/model/ye_xiu/achieves/archieves_role_entity.dart';
import 'package:flutter_eve_plugin/model/ye_xiu/achieves/archieves_weapon_entity.dart';
import 'package:flutter_eve_plugin/pages/ye_xiu/archives/actions.dart';
import 'package:flutter_eve_plugin/route/main.dart';
import 'package:flutter_eve_plugin/store/main.dart';
import 'package:flutter_eve_plugin/store_vm/app_vm.dart';
import 'package:flutter_eve_plugin/utils/print_util.dart';
import 'package:flutter_redux/flutter_redux.dart';

class ArchivesRoleWidget extends StatelessWidget {

  const ArchivesRoleWidget({
    Key key,
  }) : super(key: key);


  @override
  Widget build(BuildContext context) {
    ArchievesRoleCardinfo cardinfo;
    ArchievesRoleRoleinfo roleInfo;
    ArchievesWeaponEntity weaponEntity;

    return StoreConnector<AppState, AppStateViewModel>(
        converter: (store) => AppStateViewModel(state: store.state),
        onInit: (store) {
          store.dispatch(initData());
        },
        builder: (context, vm) {
          cardinfo = vm.state.yeXiuState.archivesState.archievesRoleEntity.cardInfo;
          logPrint('AchievesRoleCardinfo data $cardinfo --- ${cardinfo?.cardId} ');
          if (cardinfo == null) {
            cardinfo = ArchievesRoleCardinfo(maxLevel: 0 ,harvest: [],description: '',updateTime: '',operatorName: '',
                quality: 0,classesId: 0,cardId: '',professionName: '',name: '',id: 0);
          }

          roleInfo =
              vm.state.yeXiuState.archivesState.archievesRoleEntity.roleInfo;
          if (roleInfo == null) {
            roleInfo = ArchievesRoleRoleinfo(
                cardLevel: ArchievesRoleRoleinfoCardlevel(
                    res: 0,
                    def: 0,
                    level: 0,
                    consumables: [],
                    hp: 0,
                    updateTime: '',
                    cardId: '',
                    atk: 0,
                    id: 0),
                upgradable: null,
                upgradeLevel: null,
                goods: [],
                fightingCapacity: 0,
                upgradeFightingCapacity: 0);
          }
          weaponEntity = vm.state.yeXiuState.archivesState.archievesWeaponEntity;
          logPrint('weaponEntity get');
          return SingleChildScrollView(
            child: Column(
              mainAxisAlignment: MainAxisAlignment.start,
              crossAxisAlignment: CrossAxisAlignment.start,
              children: <Widget>[
                ArchivesTopWidget(),
                ArchivesCenterWidget(info: roleInfo,cardinfo: cardinfo),
                GestureDetector(
                  onTap: () {
                    Navigator.pushNamed(context, RouteConstant.ArchivesUpgradePage);
                  },
                  child: ArchivesFooterWidget(weaponEntity: weaponEntity),
                )
              ],
            ),
          );
        });
  }


}
